from Tkinter import *
import re,threading

interface = True

class window:
	def __init__(self,daft):
		self.daft = daft
		self.root = Tk() #create our tk window
		self.root.title('DAFT') #give it a title
		self.w = Text(self.root,relief=GROOVE,wrap=WORD,height=8,width=32) #this is the message display
		self.w.tag_config("bot",font="sans 10 bold")
		self.w.tag_config("man",font="sans 10")
		self.w.config(state=DISABLED)
		self.w.pack() #here w attach it to our tkinter window
		self.x = Entry(self.root) #here we have our text entry field
		self.x.pack() #and attach text entry to 
		self.root.bind_all('<Return>', self.boom)

	def tick(self):
		tickval = self.daft.tick()
		if tickval:
			self.botr(tickval)
		self.root.after(10, self.tick)

	def boom(self,event):
		got = self.x.get()
		self.manr(got)
		r = self.daft.boom(got,"desktop")

	def botr(self,text):
		self.w.config(state=NORMAL)
		self.w.insert(END,"\n"+text,("bot"))
		self.w.see(END)
		self.w.config(state=DISABLED)
	def manr(self,text):
		self.w.config(state=NORMAL)
		self.w.insert(END,"\n"+text,("man"))
		self.w.see(END)
		self.w.config(state=DISABLED)

	def say(self.r):
		self.botr(r)
		self.x.delete(0,len(got))
	def close(self):
		pass

def tick(daft):
	pass

class thread ( threading.Thread ):
	def __init__(self,daft):
		threading.Thread.__init__(self)
		self.daft = daft
	def run ( self ):
		global w
		w = window(self.daft)
		w.tick()
		w.root.mainloop()
		w.close()

def say(r):
	w.say(r);

